package com.kgc.ebook.ebookmanager.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.ebook.ebookmanager.mapper.EbookentryMapper;
import com.kgc.ebook.ebookmanager.pojo.Ebookentry;
import com.kgc.ebook.ebookmanager.pojo.EbookentryExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EbookentrySreviceImpl implements  EbookentrySrevice {
@Resource
EbookentryMapper ebookentryMapper;
    @Override
    public PageInfo<Ebookentry> select(Integer pageNum, Integer pageSize, Integer categoryId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Ebookentry> entries;
        if (categoryId!=0){
            EbookentryExample entryExample=new EbookentryExample();
            EbookentryExample.Criteria criteria = entryExample.createCriteria();
            criteria.andCategoryidEqualTo(categoryId);
           entries = ebookentryMapper.selectByExample(entryExample);
        }else {
            entries = ebookentryMapper.selectByExample(null);
        }

        PageInfo<Ebookentry> pageInfo=new PageInfo<>(entries);
        System.out.println("测试成功!!!");
        return pageInfo;

    }

    @Override
    public Integer add(Ebookentry entry) {
int i=ebookentryMapper.insert(entry);
        return i;
    }

    @Override
    public Ebookentry selectByid(Integer id) {
        Ebookentry ebookentry=ebookentryMapper.selectByPrimaryKey(id);
        return ebookentry;
    }

    @Override
    public Integer update(Ebookentry entry) {
        int i=ebookentryMapper.updateByPrimaryKeySelective(entry);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
     int i= ebookentryMapper.deleteByPrimaryKey(id);
        return i;
    }
}
